<?php
class Com_model extends CI_Model {

    public function __construct()
    {
      $this->load->database();
    }
		  
	public function get_news($table_field, $keywords, $reg_capital, $per_page='', $offset=0)
	{
//		$tableName = $array['table_name'];
//		$company = $array['company'];
//	    $city = $array['city'];
//	    $product = $array['product'];
//	    $registerMoney = $array['register_money'];
	    $companySlt = array( 
	  			    'b.company_name', 'b.legal_person', 'b.registered_capital', 
	    			'c.contact_person', 'c.tel', 'c.call_phone', 'c.email', 
	    			'b.company_website', 'b.business_scope', 'c.address' ,'c.company_id'	    			
	  			    );
	  	$que_capital = '';
		if($reg_capital !== '')
		{
			$que_capital = " and b.registered_capital >= {$reg_capital}";
		}
	    $this->db->select($companySlt)->from('qs_contact c')
	    		 ->join('qs_business_archive b', "c.company_id = b.company_id{$que_capital}")
	    		 ->like($table_field, $keywords);
	    if($per_page !== "" && $offset !== 0){
	    	$this->db->limit($per_page, $offset);
	    }
	    $query = $this->db->get();
	    return $query;
	}
	
	public function get_company_detail($company_id='')
	{
		$sql = 'SELECT c.*, b.*, p.*, h.*
				FROM qs_contact c, qs_business_archive b, qs_payment p, qs_company_honor h
				WHERE c.company_id =  ?
				AND b.company_id =  ?
				AND p.company_id =  ?
				AND h.company_id =  ?';
		$query = $this->db->query($sql, array($company_id, $company_id, $company_id, $company_id));
		return $query->row_array();
	}
}